package com.sgb.jicai.viewmodel;

import androidx.lifecycle.ViewModel;

import com.sgb.jicai.base.JiCaiBaseApi;
import com.sgb.jicai.entity.BaseCount;
import com.swgk.core.base.api.ICallBack;
import com.sgb.jicai.view.activity.JiCaiSearchTwoActivity;
import com.swgk.core.base.model.entity.BaseEntity;

/**
 * 第二级搜索Model
 */
public class JiCaiSearchTwoModel extends ViewModel {

    private JiCaiSearchTwoActivity activity;


    //获取需方发起数量
    public void getXuFangCount(String words) {
        JiCaiBaseApi.getApi().getXuFangCount(words).enqueue(new ICallBack<BaseEntity<BaseCount>>() {
            @Override
            public void onSuccess(BaseEntity<BaseCount> data) {
                if (data == null || data.getState() == null) {
                    return;
                }

                if (data.getState().equals(JiCaiBaseApi.RESPONSE_OK)) {
                    activity.updateTitle(0, data.getData().getCommon());
                    activity.updateTitle(2, data.getData().getMember());
                }
            }
        });
    }

    //获取供方发起数量
    public void getFactoryCount(String words) {
        JiCaiBaseApi.getApi().getFactoryCount(words).enqueue(new ICallBack<BaseEntity<Integer>>() {
            @Override
            public void onSuccess(BaseEntity<Integer> data) {
                if (data == null || data.getState() == null) {
                    return;
                }

                if (data.getState().equals(JiCaiBaseApi.RESPONSE_OK)) {
                    activity.updateTitle(1, data.getData());
                }
            }
        });
    }


    public void setActivity(JiCaiSearchTwoActivity jiCaiSearchTwoActivity) {
        this.activity = jiCaiSearchTwoActivity;
    }
}
